package com.adam.masterSpringMVC4.weibo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.List;

@Component
public class AsyncSearch {
    @Autowired
    private WeiboCache weiboCache;

    @Async
    public ListenableFuture<List<WeiboData>> asyncFetch(String searchType, String keyword) {
        System.out.println(Thread.currentThread().getName() + " Searching for " + keyword);
        return new AsyncResult<>(weiboCache.fetch(searchType, keyword));
    }
}
